package com.gx.smart.building.ui.knowledge.fragment

import android.os.Bundle
import android.view.ViewGroup
import com.gx.smart.base.BaseMVVMFragmentV3
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentKnowledgeBinding
import com.gx.smart.building.ui.knowledge.adapter.ItemKnowledgeTypeAdapter
import com.gx.smart.building.ui.knowledge.model.KnowledgeType
import com.gx.smart.building.ui.knowledge.viewmodel.KnowledgeViewModel

class KnowledgeFragment : BaseMVVMFragmentV3<KnowledgeViewModel>() {
    private lateinit var adapter: ItemKnowledgeTypeAdapter
    private lateinit var viewBinding: FragmentKnowledgeBinding

    companion object {
        fun newInstance(list: ArrayList<KnowledgeType>) = KnowledgeFragment().apply {
            arguments = Bundle().apply {
                putParcelableArrayList("data", list)
            }
        }
    }

    override fun onBindLayout(): Int = R.layout.fragment_knowledge

    override fun getToolbarTitle(): String = ""

    override fun enableToolbar(): Boolean = false

    override fun enableStatusBar(): Boolean = false

    override fun onBindViewModel(): Class<KnowledgeViewModel> = KnowledgeViewModel::class.java

    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentKnowledgeBinding.inflate(layoutInflater, root, true)
    }

    override fun initView() {
        adapter = ItemKnowledgeTypeAdapter(requireContext())
        viewBinding.recyclerView.adapter = adapter
    }

    override fun initData() {
        val list = arguments?.getParcelableArrayList<KnowledgeType>("data")
        adapter.addAll(list)
    }
}